package com.yanqu.road.server.gameplayer.module.player.beauty;

import com.yanqu.road.entity.config.beauty.BeautyInfo;
import com.yanqu.road.entity.config.skill.SkillInfo;
import com.yanqu.road.entity.config.skill.SkillUpgradeInfo;
import com.yanqu.road.entity.enums.eBeautySkillType;
import com.yanqu.road.entity.player.UserBeauty;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BeautyModule;
import com.yanqu.road.server.manger.config.BeautyMgr;
import com.yanqu.road.server.manger.config.SkillMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.property.Property;

public abstract class BeautyUpgradeSkillAction {

    //美女
    int beautyId;

    //位置
    int position;

    //技能类型
    int skillType;

    //请求升级次数
    int batch;

    //可升级次数
    int realBatch;

    //升级前技能等级
    int oldLv = Integer.MAX_VALUE;

    //计算结果
    int ret;

    //消耗
    Property consumer = new Property();

    long needConsume;

    //玩家
    GamePlayer player;

    BeautyModule beautyModule;

    public BeautyUpgradeSkillAction(int beautyId, int position, int skillType, int batch, BeautyModule beautyModule, GamePlayer player) {
        this.beautyId = beautyId;
        this.position = position;
        this.skillType = skillType;
        this.batch = batch;
        this.player = player;
        this.beautyModule = beautyModule;
        setOldLv();
    }

    //验证参数
    public void preValidArgument(){
        UserBeauty userBeauty = beautyModule.getUserBeauty(beautyId);
        if (!BeautyMgr.isUserBeautyExist(userBeauty)) {
            this.ret = GameErrorCode.E_BEAUTY_NO_FOUND;
            return;
        }
        BeautyInfo beautyInfo = BeautyMgr.getBeautyInfo(beautyId);
        if (beautyInfo == null) {
            this.ret = GameErrorCode.E_BEAUTY_NO_FOUND;
            return;
        }
        eBeautySkillType eType = eBeautySkillType.forValue(skillType);
        if (eType == null) {
            this.ret = GameErrorCode.E_BEAUTY_PATRONS_SKILL_ERR;
        }
    }

    public void checkMaxLv() {
        SkillInfo skillInfo = getSkillInfo();
        if (skillInfo == null) {
            return;
        }
        SkillUpgradeInfo nextUpgradeInfo = SkillMgr.getSkillUpgradeInfo(skillInfo.getUpgradeType(0), oldLv + 1);
        if (null == nextUpgradeInfo) {
            this.ret = GameErrorCode.E_BEAUTY_LEVEL_MAX;
        }
    }

    public abstract void setOldLv();

    public abstract SkillInfo getSkillInfo();

    //计算消耗及升级次数
    public abstract void calConsumer();

    public abstract void upgrade();


    public int getBeautyId() {
        return beautyId;
    }

    public int getPosition() {
        return position;
    }

    public int getSkillType() {
        return skillType;
    }

    public int getRealBatch() {
        return realBatch;
    }

    public int getOldLv() {
        return oldLv;
    }

    public int getRet() {
        return ret;
    }

    public Property getConsumer() {
        return consumer;
    }

    public long getNeedConsume() {
        return needConsume;
    }

    public static BeautyUpgradeSkillAction getAction(int beautyId, int position, int skillType, int batch, BeautyModule beautyModule, GamePlayer player){
        if(skillType == eBeautySkillType.GlamourAddPatronsFixedValue.getValue()){
            return new GlamourAddPatronsFixedValue(beautyId, position, skillType, batch, beautyModule, player);
        }else if(skillType == eBeautySkillType.GlamourAddPatronsMultiValue.getValue()){
            return new GlamourAddPatronsMultiValue(beautyId, position, skillType, batch, beautyModule, player);
        }else if(skillType == eBeautySkillType.EscortAddPatronsFixedValue.getValue()){
            return new EscortAddPatronsFixedValue(beautyId, position, skillType, batch, beautyModule, player);
        }else if(skillType == eBeautySkillType.EscortAddPatronsMultiValue.getValue()){
            return new EscortAddPatronsMultiValue(beautyId, position, skillType, batch, beautyModule, player);
        }else if(skillType == eBeautySkillType.SkinAddOccupationQuality.getValue()){
            return new SkinAddOccupationQuality(beautyId, position, skillType, batch, beautyModule, player);
        }else if(skillType == eBeautySkillType.SkinAddOccupationMulti.getValue()){
            return new SkinAddOccupationMulti(beautyId, position, skillType, batch, beautyModule, player);
        }else if(skillType == eBeautySkillType.PeerlessPromotionSkill.getValue()){
            return new PeerlessPromotionSkill(beautyId, position, skillType, batch, beautyModule, player);
        }else if(skillType == eBeautySkillType.PeerlessSkill.getValue()){
            return new PeerlessSkill(beautyId, position, skillType, batch, beautyModule, player);
        }else if(skillType == eBeautySkillType.MusicRoomAddPatrons.getValue()){
            return new MusicRoomAddPatrons(beautyId, position, skillType, batch, beautyModule, player);
        } else if(skillType == eBeautySkillType.TravelBookAlbumSkill.getValue()){
            return new TravelBookAlbumSkill(beautyId, position, skillType, batch, beautyModule, player);
        }
        return null;
    }
}
